1.將index.js的頁面,指派到Router.js
import React from 'react';
import ReactDOM from 'react-dom';
import Router from 'Router';
ReactDOM.render(<Router />,document.getElementById('root'))
2.再由Router.js去指派要呼叫那個元件
Router.js
import App from 'pages/App.js'
import Login from 'pages/login.js'
import NotFound from 'pages/NotFound'
import {BrowserRouter,Switch,Route} from 'react-router-dom'
const Router =()=>(
<BrowserRouter>
<Switch>
<Route path='/' exact component={App} />
<Route path='/login' component={Login} />
<Route component={NotFound}/> //找不到就用這一個
</Switch>
</BrowserRouter>
)
export default Router;